<?php
// +----------------------------------------------------------------------
// | Created by Sublime: [ Conqweal ]
// +----------------------------------------------------------------------
// | Copyright (c) 2021~20223[chenjia] All rights reserved.
// +----------------------------------------------------------------------
// | SiteUrl: http://www.99dn.cn
// +----------------------------------------------------------------------
// | Author: Conqweal <150672834@qq.com>
// +----------------------------------------------------------------------
// | Date: 2021/12/22 0026
// +----------------------------------------------------------------------
// | Description:稿件管理
// +----------------------------------------------------------------------


namespace app\admin\controller;
use app\BackendController;
use app\admin\model\MissionSchedule as cmodel;
use think\facade\Cache;
use support\Request;
use think\facade\Db;

class MissionScheduleController extends BackendController
{
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index()
    {
     
        $status        = cmodel::getStatus();         
        $status_options = output_select($status, []);
        return view('missionschedule/index', compact('status_options'));
    }

    /**
     * 列表json数据
     * @param  Request $request [请求变量]
     * @return [type]           [json数据]
     */
    public function listData(Request $request)
    {
        $limit = $request->get('limit', 10);
        $w     = [];

        if ($request->get('title')) {
            $w[] = ['b.title', 'like', '%' . $request->get('title') . '%'];

        }
        if ($request->get('content')) {
            $w[] = ['a.content', 'like', '%' . $request->get('content') . '%'];

        }
       

        if ($request->get('status')) {
            $w[] = ['a.status', '=', $request->get('status')];

        }

        
        $q = cmodel::alias('a')->join("mission_description b", "a.mission_id=b.mission_id", 'left')->field("a.*,b.title")->where($w);
         
        $q->order("id","desc");
        $ls     = $q->paginate(['list_rows' => $limit, 'request' => $request->all()]);
        $res    = $ls->items();
        $status = cmodel::getStatus();
        $res    = array_map(function ($v) use ($status) {
             $v->content = msubstr($v->content,0,30);
            $v->status_txt = $status[$v->status];
            $v->user_info = $v->user_info;
            $v->profile = $v->user_info->profile;
            return $v;
        }, $res);

        return json(['code' => $ls->total() > 0 ? 0 : 201, 'msg' => '无数据', 'count' => $ls->total(), 'data' => $res]);
    }

    
  
 

    

}
